﻿using System;

namespace SiMay.Sockets.Tcp.TcpConfiguration
{
    /// <summary>
    /// Tcp连接配置信息
    /// </summary>
    public class TcpSocketConfigurationBase : ITcpSocketSaeaConfiguration
    {
        public TcpSocketConfigurationBase()
        {
            CompressTransferFromPacket = false;//是否压缩数据
            ReceiveBufferSize = 8192;//接收数据缓存区大小
            SendBufferSize = 1024 * 1024 * 2;//默认2m，避免多次send，可根据自己的应用设置最优参数值
            ReceiveTimeout = TimeSpan.Zero;
            SendTimeout = TimeSpan.Zero;
            NoDelay = true;//是否开启nagle算法
            AppKeepAlive = true;//是否使用自定义的心跳包检测
            KeepAlive = false;//是否使用操作系统默认的心跳包检测
            KeepAliveInterval = 5000;//心跳包多长时间开始第一次探测
            KeepAliveSpanTime = 1000; //心跳包探测时间间隔
            ReuseAddress = true;//是否重用IP地址
        }

        /// <summary>
        /// 是否为服务器配置 true为服务器配置  false为客户端配置
        /// </summary>
        internal bool _intervalWhetherService { get; set; }

        /// <summary>
        /// 是否压缩数据,如果开启压缩传输速度将减半
        /// </summary>
        public bool CompressTransferFromPacket{ get; set; }
        
        /// <summary>
        /// 接收数据缓存区
        /// </summary>
        public int ReceiveBufferSize { get; set; }

        /// <summary>
        /// 发送数据缓存区,默认2m，避免多次send，可根据自己的应用设置最优参数值
        /// </summary>
        public int SendBufferSize { get; set; }

        /// <summary>
        /// 该值指定之后同步 Receive 调用将超时的时间长度
        /// </summary>
        public TimeSpan ReceiveTimeout { get; set; }

        /// <summary>
        /// 该值指定之后同步 Send 调用将超时的时间长度。
        /// </summary>
        public TimeSpan SendTimeout { get; set; }

        /// <summary>
        /// 是否开启nagle算法
        /// </summary>
        public bool NoDelay { get; set; }

        /// <summary>
        /// 是否由程序发送心跳包检测
        /// </summary>
        public bool AppKeepAlive { get; set; }

        /// <summary>
        /// 是否使用操作系统检测心跳包,默认否
        /// </summary>
        public bool KeepAlive { get; set; }

        /// <summary>
        /// 系统检测心跳包,多长时间开始第一次探测
        /// </summary>
        public int KeepAliveInterval { get; set; }

        /// <summary>
        /// 系统检测心跳包,探测时间间隔
        /// </summary>
        public int KeepAliveSpanTime { get; set; }

        /// <summary>
        /// 是否重用IP地址
        /// </summary>
        public bool ReuseAddress { get; set; }
    }
}
